package com.edu.exam.entity.curriculum.questionbank;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import jakarta.validation.constraints.DecimalMin;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 论述题评分标准实体类
 * 对应数据库表：scoring_criterion
 * 
 * 管理论述题的评分标准信息，包括评分标准名称、描述、总分、评分类型等。
 * 支持评分等级的创建、激活/停用管理。
 * 关联论述题实体、创建人等信息。
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Comment("论述题评分标准表")
@SQLDelete(sql = "UPDATE scoring_criterion SET is_deleted = true, delete_time = CURRENT_TIMESTAMP WHERE id = ?")
@Where(clause = "is_deleted = false")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class ScoringCriterion {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @NotNull(message = "题目ID不能为空")
    @Column(name = "question_id", nullable = false)
    @Comment("关联题目ID")
    private Long questionId;

    @NotBlank(message = "评分标准名称不能为空")
    @Size(max = 100, message = "评分标准名称长度不能超过100个字符")
    @Column(name = "criterion_name", nullable = false, length = 100)
    @Comment("评分标准名称")
    private String criterionName;

    @Column(name = "description", columnDefinition = "TEXT")
    @Comment("评分标准描述")
    private String description;

    @NotNull(message = "总分不能为空")
    @DecimalMin(value = "0.0", message = "总分不能为负数")
    @Column(name = "total_score", nullable = false, precision = 10, scale = 2)
    @Comment("总分")
    private BigDecimal totalScore;

    @NotBlank(message = "评分类型不能为空")
    @Size(max = 30, message = "评分类型长度不能超过30个字符")
    @Column(name = "scoring_type", nullable = false, length = 30)
    @Comment("评分类型")
    private String scoringType;

    @NotNull(message = "等级数量不能为空")
    @Column(name = "level_count", nullable = false)
    @Comment("等级数量")
    private Integer levelCount;

    @NotBlank(message = "状态不能为空")
    @Column(name = "status", nullable = false, length = 20)
    @Comment("状态")
    private String status;

    @NotNull(message = "创建人ID不能为空")
    @Column(name = "creator_id", nullable = false)
    @Comment("创建人ID")
    private Long creatorId;

    @NotNull(message = "创建时间不能为空")
    @Column(name = "created_time", nullable = false)
    @Comment("创建时间")
    private LocalDateTime createdTime;

    @NotNull(message = "更新时间不能为空")
    @Column(name = "updated_time", nullable = false)
    @Comment("更新时间")
    private LocalDateTime updatedTime;

    @Column(name = "activate_time")
    @Comment("激活时间")
    private LocalDateTime activateTime;

    @Column(name = "deactivate_time")
    @Comment("停用时间")
    private LocalDateTime deactivateTime;

    @NotNull(message = "删除标志不能为空")
    @Column(name = "is_deleted", nullable = false)
    @Comment("是否删除")
    @Builder.Default
    private Boolean isDeleted = false;

    @Column(name = "delete_time")
    @Comment("删除时间")
    private LocalDateTime deleteTime;

    @Size(max = 500, message = "删除原因长度不能超过500个字符")
    @Column(name = "delete_reason", length = 500)
    @Comment("删除原因")
    private String deleteReason;

    @Column(name = "scoring_rules", columnDefinition = "TEXT")
    @Comment("评分规则(JSON格式)")
    private String scoringRules;

    @Column(name = "scoring_levels", columnDefinition = "TEXT")
    @Comment("评分等级(JSON格式)")
    private String scoringLevels;

    @Column(name = "meta_data", columnDefinition = "TEXT")
    @Comment("扩展元数据(JSON格式)")
    private String metaData;
}